package com.tetris.test;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

import com.tetris.controller.Controller;
import com.tetris.entities.Ground;
import com.tetris.entities.ShapeFactory;
import com.tetris.util.Constants;
import com.tetris.view.GamePanel;
import com.tetris.view.ScorePanel;


/**
 * 俄罗斯方块
 */
public class Game {

	public static void main(String[] args) {
		ShapeFactory shapeFactory = new ShapeFactory();
		Ground ground = new Ground();
		GamePanel gamePanel = new GamePanel();
		ScorePanel scorePanel = new ScorePanel();
		
		JFrame jframe = new JFrame();
		jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		// exe4j 打包时使用
		// jframe.setSize(gamePanel.getSize().width + 16 + 200, gamePanel.getSize().height + 29);
		// 调试运行时使用
		jframe.setSize(gamePanel.getSize().width + 16 + 200, gamePanel.getSize().height + 39);
		jframe.setTitle(Constants.GAME_NAME);
		jframe.setLocationRelativeTo(null);	// 窗口居中
		jframe.setResizable(false);	// 禁用调整窗口大小
		jframe.setUndecorated(false);	// 禁用最大化窗口按钮
		
		ImageIcon imageIcon = new ImageIcon(Game.class.getResource("/icon.png"));  
		jframe.setIconImage(imageIcon.getImage());
		
		Controller controller = new Controller(shapeFactory, ground, gamePanel, scorePanel, jframe);
		jframe.addKeyListener(controller);

		jframe.add(gamePanel);
		jframe.add(scorePanel);
		gamePanel.setBounds(0, 0, gamePanel.getSize().width, gamePanel.getSize().height);
		scorePanel.setBounds(gamePanel.getSize().width, 0, 200, gamePanel.getSize().height);
		jframe.setLayout(null);// 设置空布局，即绝对布局
		
		jframe.setVisible(true);
		scorePanel.controllButtonFocus();

		gamePanel.addKeyListener(controller);
	}
}
